package system

import (
	"context"
	"github.com/gogf/gf/v2/util/gutil"
	"zuhao-seucre/internal/dao"
	"zuhao-seucre/internal/model/entity"

	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"

	"zuhao-seucre/api/system/v1"
)

func (c *ControllerV1) Value(ctx context.Context, req *v1.ValueReq) (res *v1.ValueRes, err error) {
	var (
		config entity.TSysConfig
	)

	err = dao.TSysConfig.Ctx(ctx).Where(dao.TSysConfig.Columns().Key, req.Key).Scan(&config)

	if err != nil {
		err = gerror.Wrap(err, "sql执行异常")
		return
	}

	if gutil.IsEmpty(config.Value) {
		err = gerror.NewCode(gcode.CodeNotFound)
		return
	}
	res = new(v1.ValueRes)
	*res = v1.ValueRes(config.Value)
	return
}
